package app.server.project.main.service.db.entity.user;

import app.server.project.core.syndb.SynDBMgr;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Transient;
import lombok.Data;
import org.hibernate.annotations.Comment;

@Data
@Entity(name = "solana_info")
@TableName("solana_info")
@Comment(value = "solana区块信息")
public class SolanaInfoEntity {

    @Id
    @Column(name = "id")
    @Comment("用户主键")
    @TableId("id")
    private int id;

    @TableField("num")
    @Column(name = "num")
    @Comment("数值")
    private long num;

    @JsonIgnore
    @Transient
    @TableField(exist = false)
    private boolean synDb = false;

    public static SolanaInfoEntity of(int id) {
        SolanaInfoEntity userInfoEntity = new SolanaInfoEntity();
        userInfoEntity.setId(id);
        userInfoEntity.setSynDb(true);
        return userInfoEntity;
    }

    public void setNum(long num) {
        this.num = num;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(SolanaInfoEntity::getNum, this);
    }


}
